<template>
  <div>
    <div>vue star url is {{url}}</div>
    <div>vue star url is {{url2}}</div>
  </div>
</template>

<script>

import axios from 'axios'// 导入所需要的ajax插件

export default {
  name: 'App',
  data () {
   return {
     url: '',// 返回的数据
     url2: ''
   }
  },
  mounted () {// 初始化加载

    const gitUtl = 'https://api.github.com/search/repositories?q=v&sort=stars'

    // vue-resource请求：
    this.$http.get(gitUtl).then((response) => { // then返回的是promise异步处理对象
      // success callback
      const result = response.data
      console.log(result) //返回结果数据
      this.url = result.items[0].owner.url;
    }, (response) => {
      // error callback
      console.log(response.statusText) //错误信息
    })

    //axios请求：
    axios.get(gitUtl).then(response => {
      const result = response.data
      console.log(result) //返回结果数据
      this.url2 = result.items[0].owner.url;
      })
      .catch(error => {
        console.log(error.message)
      })

  }
}
</script>

<style>

</style>
